package com.dragon.mmochat.message;

import java.util.List;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.deal.MmochatBigMoneyDeal;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.skymobi.buffer.SkymobiBuffer;
import com.skymobi.message.SkymobiProtocolMessage;

public class Mmochat_18_2S extends SkymobiProtocolMessage {
	int hallState;
	List<MmochatBigMoneyDeal> sellOrderList;
	List<MmochatBigMoneyDeal> buyOrderList;
	List<MmochatBigMoneyDeal> myOrderList;
	MmochatPlayer me;
	int sellPageNo;
	int totalSellPageNum;
	int buyPageNo;
	int totalBuyPageNum;

	public Mmochat_18_2S() {
		setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_18_2);
	}

	@Override
	protected void encodeBody(SkymobiBuffer out) {
		out.putUnsignedShort(hallState);
		out.putShort((short) sellPageNo);
		out.putShort((short) totalSellPageNum);
		out.putShort((short) sellOrderList.size());
		for (MmochatBigMoneyDeal deal : sellOrderList) {
			out.putInt(deal.getId());
			out.putInt(deal.getType().getKey());
			out.putInt(deal.getPrice());
			out.putInt(deal.getRest());
			long restTime = Math
					.max(0,
							MmochatConstant.bigmoneyDealOrderLifeTime
									- (System.currentTimeMillis() - deal
											.getStartTick()));
			int hour = (int) (restTime / MmochatConstant.MS_PER_HOUR);
			out.putInt(hour);
		}

		out.putShort((short) buyPageNo);
		out.putShort((short) totalBuyPageNum);
		out.putShort((short) buyOrderList.size());
		for (MmochatBigMoneyDeal deal : buyOrderList) {
			out.putInt(deal.getId());
			out.putInt(deal.getType().getKey());
			out.putInt(deal.getPrice());
			out.putInt(deal.getRest());
			long restTime = Math
					.max(0,
							MmochatConstant.bigmoneyDealOrderLifeTime
									- (System.currentTimeMillis() - deal
											.getStartTick()));
			int hour = (int) (restTime / MmochatConstant.MS_PER_HOUR);
			out.putInt(hour);
		}

		out.putInt(me.getAccount_bigmoney());
		out.putInt(me.getAccount_smallmoney());
		out.putShort((short) myOrderList.size());
		for (MmochatBigMoneyDeal deal : myOrderList) {
			out.putInt(deal.getId());
			out.putInt(deal.getType().getKey());
			out.putInt(deal.getPrice());
			out.putInt(deal.getRest());
			long restTime = Math
					.max(0,
							MmochatConstant.bigmoneyDealOrderLifeTime
									- (System.currentTimeMillis() - deal
											.getStartTick()));
			int hour = (int) (restTime / MmochatConstant.MS_PER_HOUR);
			out.putInt(hour);
		}
	}

	public void setSellOrderList(List<MmochatBigMoneyDeal> sellOrderList) {
		this.sellOrderList = sellOrderList;
	}

	public void setBuyOrderList(List<MmochatBigMoneyDeal> buyOrderList) {
		this.buyOrderList = buyOrderList;
	}

	public void setMyOrderList(List<MmochatBigMoneyDeal> myOrderList) {
		this.myOrderList = myOrderList;
	}

	public void setMe(MmochatPlayer me) {
		this.me = me;
	}

	public void setHallState(int hallState) {
		this.hallState = hallState;
	}

	public void setSellPageNo(int sellPageNo) {
		this.sellPageNo = sellPageNo;
	}

	public void setBuyPageNo(int buyPageNo) {
		this.buyPageNo = buyPageNo;
	}

	public void setTotalSellPageNum(int totalSellPageNum) {
		this.totalSellPageNum = totalSellPageNum;
	}

	public void setTotalBuyPageNum(int totalBuyPageNum) {
		this.totalBuyPageNum = totalBuyPageNum;
	}

}
